package kr.hyunist.androidcomplete01saeildamil.ch19;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class BackWorkEx01 extends Activity {
	TextView mResult;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.backworkex);
		
		mResult = (TextView) findViewById(R.id.backworkstarttv);
	}
	
	public void mOnClick(View v){
		int start = 0, end = 100;
		int result;
		setProgressBarIndeterminateVisibility(true);
		result = Accumulate(start, end);
		mResult.setText("" + result);
		setProgressBarIndeterminateVisibility(false);
	}

	private int Accumulate(int start, int end) {
		int sum = 0;
		for(int i = start; i <= end; i++){
			sum += i;
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return sum;
	}
}
